<%--
  Created by IntelliJ IDEA.
  User: 仲春初九
  Date: 2019/11/23
  Time: 10:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/admin/css/admin.css" />


    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/uploadPreview.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/static/admin/js/common.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" href="layui/css/layui.css"  media="all">
</head>
<body>
<form id="addComm" method="post" action="${pageContext.request.contextPath}/CommServlet.action?flag=save"
      enctype="multipart/form-data">
    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="cname" lay-verify="title" autocomplete="off"
                   placeholder="请输入商品名称" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">商品图片</label>
        <div class="layui-input-block">
            <input type="file" id="logo" name="cface">
            <img id="ImgPr" class="pull-left" style="width: 120px; height: 120px;" src=""/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">商品价格</label>
        <div class="layui-input-block">
            <input type="text" name="cprice" lay-verify="title" value="" autocomplete="off"
                   placeholder="请输入价格" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">供应商选择</label>
        <div class="layui-input-block">
            <select name="cprovider" id="providerSelect" lay-filter="aihao">

            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">商品类型</label>
        <div class="layui-input-block">
            <select name="ctype" id="sele" lay-filter="aihao">

            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">库存</label>
        <div class="layui-input-block">
            <input type="text" name="cnum" lay-verify="title" value="" autocomplete="off"
                   placeholder="请输入库存" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="margin-left: 30px; padding-left: 10px;">
        <div class="layui-input-block">
            <input type="submit" class="layui-btn layui-btn-primary" value="立即提交">
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script>
    $(function () {
        $("#logo").uploadPreview({ Img: "ImgPr", Width: 220, Height: 220 });

        $.get("${pageContext.request.contextPath}/CommServlet.action?flag=proFindAll&xx="+Math.random(),"",function(data){
            for(var i=0;i< data.length;i++){
                $("#providerSelect").append("<option value='"+data[i].pid+"'>"+data[i].pname+"</option>");
            }
            form.render();//如果这段代码无法显示下拉菜和单选钮中的数据
        },"json");

        $.get("${pageContext.request.contextPath}/CommServlet.action?flag=typeFindAll&xx="+Math.random(),"",function(data){
            for(var i=0;i< data.length;i++){
                $("#sele").append("<option value='"+data[i].tid+"'>"+data[i].tname+"</option>");
            }
            form.render();//如果这段代码无法显示下拉菜和单选钮中的数据
        },"json");
    });

    <%--layui.use(['form'], function() {--%>
        <%--var form = layui.form();--%>
        <%--form.render();--%>
        <%--form.on('submit(formDemo)', function(data) {--%>
            <%--$.post("${pageContext.request.contextPath}/CommServlet.action?flag=commSave",$("#addComm").serialize(),--%>
                <%--function (result) {--%>

                    <%--var result=eval('('+result+')');--%>
                    <%--if(result.error){--%>
                        <%--alert(result.error);--%>
                    <%--}else{--%>
                        <%--layer.msg('修改成功！', {--%>
                            <%--icon: 1,--%>
                            <%--time: 1000 //2秒关闭（如果不配置，默认是3秒）--%>
                        <%--}, function(){--%>
                            <%--form.render();--%>
                            <%--var index = parent.layer.getFrameIndex(window.name);--%>
                            <%--parent.layer.close(index);--%>
                        <%--});--%>
                    <%--}--%>
                <%--},--%>
                <%--"text"--%>
            <%--);--%>
            <%--return false;--%>
        <%--});--%>
        <%--form.render();--%>
    <%--});--%>

</script>
</html>
